package cn.com.lsy.product.lepao.service.impl;

import cn.com.lsy.product.lepao.common.Constant;
import cn.com.lsy.product.lepao.model.dao.LpCourseTblMapper;
import cn.com.lsy.product.lepao.model.dao.LpCourseTypeTblMapper;
import cn.com.lsy.product.lepao.model.dao.LpCourseVideoTblMapper;
import cn.com.lsy.product.lepao.model.entities.LpCourseTbl;
import cn.com.lsy.product.lepao.model.entities.LpCourseTypeTbl;
import cn.com.lsy.product.lepao.model.entities.LpCourseTypeTblExample;
import cn.com.lsy.product.lepao.model.entities.LpCourseVideoTbl;
import cn.com.lsy.product.lepao.model.mt.dao.MtCourseMapper;
import cn.com.lsy.product.lepao.model.mt.dao.MtCourseVideoMapper;
import cn.com.lsy.product.lepao.service.ICourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CourseService implements ICourseService {

    @Autowired
    LpCourseTypeTblMapper lpCourseTypeTblMapper;
    @Autowired
    MtCourseMapper mtCourseMapper;
    @Autowired
    LpCourseTblMapper lpCourseTblMapper;
    @Autowired
    MtCourseVideoMapper mtCourseVideoMapper;
    @Autowired
    LpCourseVideoTblMapper lpCourseVideoTblMapper;

    @Override
    public List<LpCourseTypeTbl> selectCourseType() {

        LpCourseTypeTblExample example = new LpCourseTypeTblExample();
        example.createCriteria().andStatusNotEqualTo(Constant.status.deleted);

        return lpCourseTypeTblMapper.selectByExample(example);
    }

    @Override
    public boolean insertCourseType(LpCourseTypeTbl param) {

        if (lpCourseTypeTblMapper.insertSelective(param) > 0) {

            return true;

        } else {

            return false;
        }

    }

    @Override
    public boolean updateCourseType(LpCourseTypeTbl param) {

        if (lpCourseTypeTblMapper.updateByPrimaryKeySelective(param) > 0) {

            return true;

        } else {

            return false;
        }
    }

    @Override
    public List<LpCourseTbl> selectCourseByPage(int start, int end, int typeId, String searchCondition) {

        Map<String, Object> where = new HashMap<String, Object>();
        where.put("start", start);
        where.put("end", end);
        where.put("searchCondition", searchCondition);
        where.put("typeId", typeId);

        return mtCourseMapper.selectByPage(where);
    }

    @Override
    public int selectCourseByCount(int typeId, String searchCondition) {

        Map<String, Object> where = new HashMap<String, Object>();
        where.put("searchCondition", searchCondition);
        where.put("typeId", typeId);

        return mtCourseMapper.selectByCount(where);
    }

    @Override
    public LpCourseTbl selectCourseInfo(int id) {

        return lpCourseTblMapper.selectByPrimaryKey(id);
    }

    @Override
    public boolean insertCourse(LpCourseTbl param) {

        if (lpCourseTblMapper.insertSelective(param) > 0) {

            return true;

        } else {

            return false;
        }
    }

    @Override
    public boolean updateCourse(LpCourseTbl param) {

        if (lpCourseTblMapper.updateByPrimaryKeySelective(param) > 0) {

            return true;

        } else {

            return false;
        }
    }

    @Override
    public List<LpCourseVideoTbl> selectCourseVideoByPage(int start, int end, int courseId, String searchCondition) {

        Map<String, Object> where = new HashMap<String, Object>();
        where.put("start", start);
        where.put("end", end);
        where.put("searchCondition", searchCondition);
        where.put("courseId", courseId);

        return mtCourseVideoMapper.selectByPage(where);
    }

    @Override
    public int selectCourseVideoByCount(int courseId, String searchCondition) {

        Map<String, Object> where = new HashMap<String, Object>();
        where.put("searchCondition", searchCondition);
        where.put("courseId", courseId);

        return mtCourseVideoMapper.selectByCount(where);
    }

    @Override
    public LpCourseVideoTbl selectCourseVideoInfo(int id) {

        return lpCourseVideoTblMapper.selectByPrimaryKey(id);
    }

    @Override
    public boolean updateCourseVideo(LpCourseVideoTbl param) {

        if (lpCourseVideoTblMapper.updateByPrimaryKeySelective(param) > 0) {

            return true;

        } else {

            return false;
        }
    }

    @Override
    public boolean insertCourseVideo(LpCourseVideoTbl param) {

        if (lpCourseVideoTblMapper.insertSelective(param) > 0) {

            return true;

        } else {

            return false;
        }
    }
}
